﻿<UserControl x:Class="Neudesic.Pulse.Views.ActivityListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:design="clr-namespace:Neudesic.Pulse.ViewModels.Design"
             xmlns:converter="clr-namespace:Neudesic.Pulse.Converters"
             xmlns:controls="clr-namespace:Neudesic.Pulse.Controls"
             xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>

        <DataTemplate x:Key="feedItemTemplate">
            <Grid Name="contentRow" Height="Auto" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"  Height="20" Width="20" Source="{Binding AvatarUri, Converter={StaticResource UriToBitmapImageConverter}}" VerticalAlignment="Top" Margin="5" />

                <StackPanel  Grid.Row="0" Grid.Column="1">
                    <StackPanel Orientation="Horizontal">
                        <controls:LinkLabel Content="{Binding Activity.Author.Name}" Url="{Binding PulseWebAddress}" RequestNavigate="RequestNavigate" />
                        <TextBlock Visibility="{Binding NeedsActivityLabelDisplayed, Converter={StaticResource VisibilityConverter}}"  Text="{Binding ActivityLabel}"  />
                        <controls:LinkLabel Content="{Binding ToLabel}" Url="{Binding PulseWebAddress}" RequestNavigate="RequestNavigate" Visibility="{Binding NeedsActivityLabelDisplayed, Converter={StaticResource VisibilityConverter}}" />
                    </StackPanel>

                    <TextBlock Text="{Binding Activity.Text}" TextWrapping="Wrap" />

                    <StackPanel  Orientation="Horizontal" x:Name="linkSharePanel" Background="Transparent" Visibility="{Binding Activity.ContainsLink, Converter={StaticResource VisibilityConverter}}" >
                        <Border Name="linkShareBorder" MouseLeftButtonUp="linkShareBorder_MouseLeftButtonUp" Padding="3" BorderBrush="#949A9E" BorderThickness="3">
                            <Grid Width="Auto">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Image Grid.Column="0" Source="{StaticResource DocumentImage}" Width="64" Height="64" Visibility="{Binding Activity.IsFileSharing, Converter={StaticResource VisibilityConverter}}" />
                                <Image Grid.Column="0" Source="{Binding Activity.Picture, Converter={StaticResource UriToBitmapImageConverter}}" Visibility="{Binding Activity.IsPictureOrLinkWithImage, Converter={StaticResource VisibilityConverter}}" Width="Auto" Height="Auto" VerticalAlignment="Top" />
                                <StackPanel Width="275" Grid.Column="1" Margin="2"  Visibility="{Binding Activity.IsLinkSharing, Converter={StaticResource VisibilityConverter}}">
                                    <TextBlock FontWeight="ExtraBold" Text="{Binding Activity.Caption}" TextWrapping="Wrap"  />
                                    <TextBlock Text="{Binding Activity.Description}" TextWrapping="Wrap" />
                                </StackPanel>
                            </Grid>
                        </Border>
                    </StackPanel>
                </StackPanel>

                <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                    <TextBlock Height="Auto" Text="{Binding Activity.RelativeTime}" Style="{StaticResource Timestamp}" />
                    <TextBlock Text=" - " Style="{StaticResource Timestamp}"/>
                    <TextBlock Text="{Binding Activity.TotalLikes, Converter={StaticResource LikeConverter}}" Style="{StaticResource Timestamp}" />
                </StackPanel>

                <StackPanel Margin="0,13,0,15"  Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" >
                    <ItemsControl VerticalAlignment="Top"  ItemsSource="{Binding Activity.Comments}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Height="Auto" Margin="50,0,0,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Rectangle Margin="5,0,14,0"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Fill="#949A9E" Width="3" VerticalAlignment="Stretch" />
                                    <Image Margin="0,5,5,0" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"  Height="33" Width="33"  Source="{Binding Author.Image, Converter={StaticResource UriToBitmapImageConverter}}"  VerticalAlignment="Top" HorizontalAlignment="Left"  />
                                    <controls:LinkLabel Grid.Row="0" Grid.Column="2" Content="{Binding Author.Name}" Url="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext.PulseWebAddress}" RequestNavigate="RequestNavigate" />
                                    <TextBlock Grid.Row="1" Grid.Column="2" Text="{Binding Text}" TextWrapping="Wrap" />
                                    <TextBlock Grid.Column="2" Grid.Row="2" Text="{Binding RelativeTime}" Style="{StaticResource Timestamp}" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <ItemsControl VerticalAlignment="Top"  ItemsSource="{Binding Activity.Answers}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Height="Auto" Margin="25,0,0,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Border Name="answerBox" VerticalAlignment="Top" Margin="5,0,14,0" Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Background="{Binding TotalVotes, Converter={StaticResource VoteColorConverter}}" Width="50" Height="50">
                                        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding TotalVotes}" Foreground="Black" />
                                    </Border>
                                    <controls:LinkLabel Grid.Row="0" Grid.Column="2" Content="{Binding Author.Name}" Url="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=DataContext.PulseWebAddress}" RequestNavigate="RequestNavigate" />
                                    <TextBlock  Grid.Row="1" Grid.Column="1"  Text="{Binding Text}" TextWrapping="Wrap" />
                                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
                                        <TextBlock Height="Auto" Text="{Binding RelativeTime}" Style="{StaticResource Timestamp}" />
                                        <TextBlock Text=" - " Style="{StaticResource Timestamp}"/>
                                        <TextBlock Text="{Binding TotalLikes, Converter={StaticResource LikeConverter}}" Style="{StaticResource Timestamp}" />
                                    </StackPanel>
                                    <StackPanel Margin="0,5,0,15"  Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2">
                                        <ItemsControl VerticalAlignment="Top"  ItemsSource="{Binding Path=Comments}">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <Grid Height="Auto" Margin="47,0,0,0">
                                                        <Grid.RowDefinitions>
                                                            <RowDefinition Height="Auto" />
                                                            <RowDefinition Height="Auto" />
                                                            <RowDefinition Height="Auto" />
                                                        </Grid.RowDefinitions>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="Auto" />
                                                            <ColumnDefinition Width="Auto" />
                                                            <ColumnDefinition Width="*" />
                                                        </Grid.ColumnDefinitions>
                                                        <Rectangle Margin="5,0,14,0"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Fill="#949A9E" Width="3" VerticalAlignment="Stretch" />
                                                        <Image Margin="0,5,5,0" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"  Height="33" Width="33"  Source="{Binding Author.Image, Converter={StaticResource UriToBitmapImageConverter}}"  VerticalAlignment="Top" HorizontalAlignment="Left"  />
                                                        <controls:LinkLabel Grid.Row="0" Grid.Column="2" Content="{Binding Author.Name}" Url="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}, AncestorLevel=3}, Path=DataContext.PulseWebAddress}" RequestNavigate="RequestNavigate" />
                                                        <TextBlock  Grid.Row="1" Grid.Column="2" Text="{Binding Text}" TextWrapping="Wrap" />
                                                        <TextBlock  Grid.Column="2" Grid.Row="2" Text="{Binding RelativeTime}" Style="{StaticResource Timestamp}" />
                                                    </Grid>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>
            </Grid>
        </DataTemplate>

    </UserControl.Resources>

    <toolkit:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="Checking for new activity...">
        <StackPanel d:DataContext="{d:DesignInstance design:ActivityListViewModel, IsDesignTimeCreatable=True}">
            <ListBox BorderThickness="0" ItemsSource="{Binding Path=Activities}"
    					ItemTemplate="{StaticResource feedItemTemplate}"
                        x:Name="ActivityList" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
    					Margin="0,0,0,0" Background="{x:Null}" BorderBrush="{x:Null}" />
        </StackPanel>
    </toolkit:BusyIndicator>
</UserControl>
